package com.zcl.demo.concurrent;

import java.util.concurrent.locks.ReentrantLock;

public class LockDemo {
    static int i=0;
    static ReentrantLock lock = new ReentrantLock();
    public static void main(String[] args){
        new Thread(){
            @Override
            public void run() {
                for (int j = 0; j < 1000; j++) {
                    lock.lock();
                    System.out.println(Thread.currentThread().getName()+"   "+(++i)+"");
                    lock.unlock();
                }
            }
        }.start();
        new Thread(){
            @Override
            public void run() {
                for (int j = 0; j < 1000; j++) {
                    lock.lock();
                    System.out.println(Thread.currentThread().getName()+"   "+(++i)+"");
                    lock.unlock();
                }
            }
        }.start();
    }

}
